home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / client / version / findDirectChildren.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  4.3 KB  |  169 lines

  1. /*
  2.  *   $RCSfile: findDirectChildren.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:32 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38. #include <stdio.h>
  39. #include "ess.h"
  40. #include "checking.h"
  41. #include "list.h"
  42. #include "io.h"
  43. #include "tid.h"
  44. #include "object.h"
  45. #include "bf.h"
  46. #include "chunk.h"
  47. #include "lgobject.h"
  48. #include "pool.h"
  49. #include "trace.h"
  50. #include "error.h"
  51. #include "version_graph.h"
  52. #include "version_funcs.h"
  53. #include "lg_extfuncs.h"
  54. #include "sm_macro.h"
  55.  
  56. /*
  57.  * FindDirectChildren() find all the direct children of a node.
  58.  * If a child is a tombstone, then the children of the tombstone
  59.  * are included as well, recursively.
  60.  */
  61.  
  62.  int
  63. findDirectChildren(
  64.     BUFGROUP        *bufGroup,
  65.     VERSIONGRAPH     *graph,        /* graph containing node            */
  66.     VHGNODEID        nodeId,     /* inspect children of this node    */
  67.     VHGNODEID        ignoreId,     /* do not include this child        */
  68.     LIST               *childList,    /* list of children                    */
  69.     POOL            *childListPool     /* pool of list elements        */
  70. )
  71. {
  72.     VHGNODE             *node;
  73.     VHGNODELISTELEMENT    *child;
  74.     VHGNODE             *childNode;
  75.     LGNODELIST            *childListElement;
  76.  
  77.     TRPRINT(TR_VERSION, TR_LEVEL_1, 
  78.             ("checking for working children: node %d \n", nodeId) );
  79.  
  80.     CHECK_VERSIONGRAPH_MAGIC(graph);
  81.     
  82.     /*
  83.      *  Validate  nodeId
  84.      */
  85.     if (nodeId >= graph->nodeCount) {
  86.         SM_ERROR(TYPE_WARNING, esmINTERNAL);
  87.         return(esmFAILURE);
  88.     }
  89.  
  90.     /*
  91.      *    Get a pointer to the node
  92.      */
  93.     node = &(graph->nodeArray[nodeId]);
  94.  
  95.     /*
  96.      *  Do some defensive error checking.
  97.      */
  98.     CHECK_VHGNODE_MAGIC(node);
  99.  
  100.     /*
  101.      *    Get a pointer to the first child
  102.      */
  103.     child = (VHGNODELISTELEMENT*) VHGDEREF(graph, node->children.succ);
  104.     CHECK_VHGLIST_MAGIC(child);
  105.  
  106.     /*
  107.      *    Look at each child until a working version is found or 
  108.      *    the end-of-list is reached
  109.      */
  110.     while ( child != &node->children ) {
  111.         
  112.         /*
  113.          * get a pointer to the child node
  114.          */
  115.         childNode = (VHGNODE*) VHGDEREF(graph, child->item);
  116.         CHECK_VHGNODE_MAGIC(childNode);
  117.         SM_ASSERT(LEVEL_3, childNode->flags & V_frozen);        
  118.         
  119.         /*
  120.          *    Make sure the child is not one to be ignored
  121.          */
  122.         if (childNode->id != ignoreId) {
  123.             /*
  124.              *    If the child is a tombstone, then include its children
  125.              *    as well.
  126.              */
  127.             if (childNode->flags & V_tombstone) {
  128.                 findDirectChildren(bufGroup, graph, childNode->id, VHGNULLNODE, 
  129.                                     childList, childListPool);
  130.             } else {
  131.  
  132.                 /*
  133.                  *    Include only the child
  134.                  */
  135.  
  136.                 /*
  137.                  *  First get a list element and initialize it
  138.                  */
  139.                 if ((childListElement = (LGNODELIST *) poolDeq( childListPool )) == NULL) {
  140.                     /*
  141.                      *  set the error code and return
  142.                      */
  143.                     SM_ERROR(TYPE_WARNING, esmNOFREELGNODELIST);
  144.                     return(esmFAILURE);
  145.                 }
  146.                 if (lg_GetRootNodePid(bufGroup, &node->oid, 
  147.                                       &childListElement->pid, 
  148.                                       &childListElement->slot) ) {
  149.                     return(esmFAILURE);
  150.                 }
  151.  
  152.                 /*
  153.                  *  Add it to the list
  154.                  */
  155.                 listEnq(childList, &childListElement->list);
  156.  
  157.             }
  158.         }
  159.  
  160.         /*
  161.          *    Get next child
  162.          */
  163.         child = (VHGNODELISTELEMENT*) VHGDEREF(graph, child->succ);
  164.         CHECK_VHGLIST_MAGIC(child);
  165.     }
  166.  
  167.     return(esmNOERROR);
  168. }
  169.